<?php

namespace App\Http\Requests;

/**
 * 权限request验证类
 * Class RuleMenuRequest
 * @package App\Http\Requests
 */
class RuleMenuRequest extends BaseRequest
{
    /**
     * 这个地方记得为 true, 默认为 false 会返回 403 未授权提示
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * 验证规则
     * @return string[]
     */
    public function rules()
    {
        return [
            'title'      => 'required|between:2,32' ,
            'parent_id'  => 'required|integer'  , //必须验证，但是可以为空
            'icon'       => 'present',
            'sort'       => 'required|integer',
            'url'        => 'required|between:2,255',//生成controller的字符串 比如 rule_menus/id
            'menu_title' => 'required|between:2,255',
            'is_hide'    => 'required|integer',
            'is_menu'    => 'required|integer',
            'group_id'   => 'required|integer',
            'desc'       => 'required|between:2,255',
            'company_id' => 'required|integer',
            'action'     => 'unique',
        ];
    }

    /**
     * 验证不通过提示
     * @return string[]
     */
    public function messages()
    {
        return [
            'title.required'    => '请输入权限(菜单)名称' ,
            'title.between'     => '权限名称长度为2到32个字符' ,
            'parent_id.present' => '请选择上级' ,
            'action.unique'     => '该权限action已存在,请新建其他名称action或恢复action' ,
        ];
    }

}
